<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script src="../js/jquery-3.5.1.js"></script>
	</head>
	<body>
		<a href="javascript:" >下载</a>
		<script type="text/javascript">
			$(document).ready(function() {
			   var jsonData = [
			    { id: '1001', name: 'dog', age: '10'},
			    { id: '1003', name: 'big', age: '12'},
			    { id: '1002', name: 'cat', age: '11'}
			    ];
			    jsonData.sort(function(a,b){
			    return a.age - b.age;
			    });
				$("a").click(function(){
					
			    saveJSON(jsonData, 'jsonData.json');
				});
			})
			function saveJSON(data, filename) {
			    if (!data) {
			        alert('data is null');
			        return;
			    }
			    if (!filename) filename = 'json.json'
			    if (typeof data === 'object') {
			        data = JSON.stringify(data)
			    }
			    var blob = new Blob([data]);
			    var a = $("a")[0];
			    a.download = filename;
			    a.href = window.URL.createObjectURL(blob);
			     a.click();
			    
			}

		</script>
	</body>
</html>
